package bizlogic;

import dao.DAOException;
import dao.DAOFactory;
import dao.PriorityDAO;
import model.PriorityDTO;
import java.util.ArrayList;

public class PriorityManager {

	private PriorityDAO priDAO;

	public PriorityManager() {
		priDAO = DAOFactory.loadInstance().getPriorityDAO();
	}

	@SuppressWarnings("finally")
	public ArrayList<PriorityDTO> getAll() {
		ArrayList<PriorityDTO> priAll = new ArrayList<PriorityDTO>();
		try {
			priAll = priDAO.getAll();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return priAll;
		}
	}

	@SuppressWarnings("finally")
	public PriorityDTO getPriority(int priorityCode) {
		PriorityDTO pri = new PriorityDTO();

		try {
			pri = priDAO.getPriority(priorityCode);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return pri;
		}
	}

	@SuppressWarnings("finally")
	public PriorityDTO getMaxPriority() {
		PriorityDTO pri = new PriorityDTO();

		try {
			pri = priDAO.getMaxPriority();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return pri;
		}
	}

	public String insertPriority(PriorityDTO pri) {
		String error = "";

		try {
			priDAO.insertPriority(pri);
		} catch (DAOException e) {
			error = "priority.error.oninsert";
			e.printStackTrace();
		}

		return error;
	}

	public String updatePriority(PriorityDTO pri) {
		String error = "";

		try {
			priDAO.updatePriority(pri);
		} catch (DAOException e) {
			error = "priority.error.onupdate";
			e.printStackTrace();
		}

		return error;
	}

	public String deletePriority(PriorityDTO pri) {
		String error = "";

		try {
			priDAO.deletePriority(pri);
		} catch (DAOException e) {
			error = "priority.error.ondelete";
			e.printStackTrace();
		}

		return error;
	}
}
